package com.ruoyi.project.kbjz.controller;


import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.his.system.domain.HisDepartment;
import com.ruoyi.project.kbjz.domain.HisPatient;
import com.ruoyi.project.kbjz.service.IHisPatientService;
import com.ruoyi.project.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kbjz/patient")
public class HisPatientController extends BaseController {
    @Autowired
    private IHisPatientService iHisPatientService;

    /**
     * 根据身份证编号查询患者信息
     */
//    @PreAuthorize("@ss.hasPermi('system:post:query')")
    @GetMapping(value = "/{patientPersonId}")
    public AjaxResult getInfo(@PathVariable String patientPersonId)
    {
        return AjaxResult.success(iHisPatientService.selectPatientByPersonIdService(patientPersonId));
    }
    /**
     * 新增患者
     */
//    @PreAuthorize("@ss.hasPermi('system:post:add')")
    @Log(title = "门诊挂号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addPatient(@Validated @RequestBody HisPatient hisPatient)
    {

        hisPatient.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iHisPatientService.insertPatientService(hisPatient));
    }

    /**
     * 查询所有患者信息
     */
    // @PreAuthorize("@ss.hasPermi('system:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(String patientName,String patientPersonId ,String patientMobile)
    {
        startPage();
        List<HisPatient> list = iHisPatientService.selectPatientAllService(patientName, patientPersonId, patientMobile);
        return getDataTable(list);
    }
}
